package org.example.lanhang.controller;



import org.example.lanhang.entity.TUser;
import org.example.lanhang.service.userService;
import org.example.lanhang.uservo.uservo;
import org.example.lanhang.util.PageResult;
import org.example.lanhang.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/TUser")
@CrossOrigin
public class userController {

    @Autowired
    private userService u;

    @GetMapping("/list")
        public List<TUser> list(){
            return u.findall();
        }

        //2. 分页查询学生信息
        @GetMapping("/findByPage")
        public PageResult<TUser> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
            return u.findByPage(page,pageSize);
    }
    //条件查询带分页
    @PostMapping("/search")
    public PageResult<TUser>search(@RequestParam("page") Integer page,
                                   @RequestParam("pageSize") Integer pageSize,
                                   @RequestBody(required = false)  uservo uservo){
        return u.search(page,pageSize,uservo);
    }

    //保存信息
    @PostMapping("/save")
    public R save(@RequestBody TUser tUser){
        return u.save(tUser) ? R.ok().message("保存成功"):R.error().message("保存失败");
    }


}
